#####################################################################
# File:         ComponentContext.py
# Product:      KnowledgeEngine
#
# Copyright:    Copyright (c) 2001, Faulkner Ltd.
# Author:       Brian Oliver
#
# Description:  This file defines the ComponentContext class,
#               for providing library based components with a parent and model 
#               context when traversed for creating assessment and
#               report pages
#
# See Also:     Component, ComponentLibrary
#####################################################################

#####################################################################
## KnowledgeEngine Library Imports
from Common import *

#####################################################################
## Zope Library Imports
# (none)

 
#####################################################################
## Python Library Imports
# (none)

#####################################################################
## ComponentContext Class Definition
class ComponentContext:
    """
        A volatile context for a component.  Used to provide parent
        and model contexts for components when used as a library
        component.
    """

    #---------------------------------------------------------------#

    def __init__(self, component):
        """
            Initialises the context defined by the specified component.
            The specified component defines the parent and the model,
            that components within (that use) this context require.
        """
        
        self.component = component

    #---------------------------------------------------------------#

    def getIdentity(self, component):
        """
            Returns the unique identity for the specified component
            with in this component context.
            RETURN TYPE: String
        """

        #we simply prepend the identity of the component that defines
        #the context to the specified components identity
        return self.component.getIdentity() + "_" + component.getIdentity()

    #---------------------------------------------------------------#

    def getModel(self):
        """
            Returns the Model for the component context.            
            RETURN TYPE: Model Class            
        """
        
        return self.component.getModel()

    #---------------------------------------------------------------#

    def getLibrary(self):
        """
            Returns the Library in which the component being proxied
            is located.

            RETURN TYPE: Model Class            
        """
        
        return self.getComponent().getLibrary()

    #---------------------------------------------------------------#

    def getComponent(self):
        """
            Returns the Component defining the component context.            
            RETURN TYPE: Component Class            
        """
        
        return self.component
            
    #---------------------------------------------------------------#

#####################################################################
## Class Initialisation
# (none)
